package com.wangsd.web.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangsd.web.coupon.entity.WxComponentAuth;
import com.wangsd.web.coupon.mapper.WxComponentAuthMapper;
import com.wangsd.web.coupon.service.WxComponentAuthService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator
 * @since 2019-09-25
 */
@Service
public class WxComponentAuthServiceImpl extends ServiceImpl<WxComponentAuthMapper, WxComponentAuth> implements WxComponentAuthService {

    @Resource
    WxComponentAuthMapper wxComponentAuthMapper;

    @Override
    public int saveWxComponent(WxComponentAuth componentAuth) {
        QueryWrapper<WxComponentAuth> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("authorizer_appid",componentAuth.getAuthorizerAppid());
        WxComponentAuth old = wxComponentAuthMapper.selectOne(queryWrapper);
        if (old != null) {
            componentAuth.setId(old.getId());
            wxComponentAuthMapper.updateById(componentAuth);
        } else {
            wxComponentAuthMapper.insert(componentAuth);
        }
        return 1;
    }
}
